
<html>
<head>
	<title>Register</title>
	<link rel="stylesheet" href="cs2102.css"> 

	<script type="text/javascript">

	function validateForm()
	{
		var matric = document.forms["register"]["regmatric"].value;
		var name = document.forms["register"]["regname"].value;
		var email = document.forms["register"]["regemail"].value;
		var contact = document.forms["register"]["regno"].value;
		var pass1 = document.forms["register"]["regpass1"].value;
		var pass2 = document.forms["register"]["regpass2"].value;

		if (matric == null || matric == "" || 
			name == null || name == "" || 
			email == null || email == "" ||
			pass1 == null || pass1 == "" ||
			pass2 == null || pass2 == "" ||
			contact == null || contact == "")
		{
			alert("All fields must be filled out.");
			return false;
		}
		if (pass1 != pass2)
		{
			alert("Passwords do not match.");
			return false;
		}
		var atpos = email.indexOf("@");
		var dotpos = email.lastIndexOf(".");
		if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length)
		{
			alert("Not a valid e-mail address");
			return false;
		}
		if (!/^\d+$/.test(contact))
		{
			alert("Invalid contact number");
			return false;
		}

		return true;
	}
	</script>
</head>
<body>

	<div class = "container">
		<?php session_start(); 
		print "<br><FORM><INPUT Type='button' VALUE='Back' onClick='history.go(-1);return true;'></FORM>";
		?>
	<FORM NAME = "register" ACTION="register.php" METHOD=get onsubmit="return validateForm()">
		<h1>Welcome to Stewie's Market</h1>
		<table>
			<tr>
				<td>Matric No:</td><td><input name="regmatric" type="text" size="20"></input></td>
			</tr>
			<tr>
				<td>Name</td><td><input name="regname" type="text" size="20"></input></td>
			</tr>
			<tr>
				<td>E-mail:</td><td><input name="regemail" type="text" size="20"></input></td>
			</tr>
			<tr>
				<td>Contact No:</td><td><input name="regno" type="text" size="20"></input></td>
			</tr>
			<tr>
				<td>Password:</td><td><input name="regpass1" type="password" size="20"></input></td>
			</tr>
			<tr>
				<td>Retype password:</td><td><input name="regpass2" type="password" size="20"></input></td>
			</tr>
		</table>
		<input type="submit" value="Register me"></input>

	</FORM>
</div>
</body>
</html>